package com.itheima.day06.test3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Test3 {
    private static List<User> list = new ArrayList<>();
    static {
        User u1 = new User("小明","123");
        User u2 = new User("小红","123");
        User u3 = new User("小明","123");

        Collections.addAll(list,u1,u2,u3);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入你要注册的账户名");
        String username = sc.next();
        if (verifyWhetherAccountNameExists(username)) {
            System.out.println("注册账户存在,请直接登录");
        }else {
            System.out.println("请输入您注册的密码");
            String password = sc.next();
            User user = new User(username,password);
            list.add(user);
            System.out.println("注册成功");
        }

    }

    private static boolean verifyWhetherAccountNameExists(String username) {
        for (User user : list) {
            if (username.equals(user.getUsername())) {
                return true;
            }
        }
        return false;
    }
}
